package com.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * *********************************************
 * @author Administrator
 * @FileName JarExecute.java
 * @Description执行上传HDFS功能jar
 **********************************************
 */
public class JarExecute {
	public static final Logger LOG = LoggerFactory.getLogger(JarExecute.class);
	
	public void executeJar(String jarFilePath){
		InputStream is = null;
		InputStreamReader isr = null;
		BufferedReader br = null;
		Process process = null;
		try {
			String exec = "java -jar " + jarFilePath;
			LOG.info(exec);
			Runtime runtime = Runtime.getRuntime();
			process = runtime.exec(exec);
			is = process.getInputStream();
			String systemEncoding = "GBK";
			if(System.getProperties().getProperty("os.name").contains("Linux")){
				systemEncoding = "UTF-8";
			}
			isr = new InputStreamReader(is, systemEncoding);
			br = new BufferedReader(isr);
			String line = null;
			while ((line = br.readLine()) != null) {
				LOG.info(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
